package com.prototype.improve;

/**
 * @author 薛虎
 * @date 2020/12/29 10:11
 * 原型模式(浅拷贝)
 */
public class Client {

    public static void main(String[] args) {

        System.out.println("原型模式完成对象的创建");

        Sheep sheep = new Sheep("tom", 1, "白色");


        sheep.friend = new Sheep("jack", 2, "黑色");

        Sheep sheep2 = (Sheep) sheep.clone(); //克隆
        Sheep sheep3 = (Sheep) sheep.clone(); //克隆
        Sheep sheep4 = (Sheep) sheep.clone(); //克隆
        Sheep sheep5 = (Sheep) sheep.clone(); //克隆
        Sheep sheep6 = (Sheep) sheep.clone(); //克隆


        System.out.println("sheep = " + sheep);
        System.out.println("sheep2 = " + sheep2 + "sheep2.friend=" + sheep2.friend.hashCode()); //因为指向的是同一块空间,所有对象属性值相同
        System.out.println("sheep3 = " + sheep3 + "sheep3.friend=" + sheep3.friend.hashCode());

        System.out.println(sheep == sheep2); //但是引用地址不同
    }
}
